package kr.pe.johnkim.waiting.mobile.controller;

import kr.pe.johnkim.waiting.mobile.domain.WaitingLog;
import kr.pe.johnkim.waiting.mobile.service.WaitingLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Waiting 로그 관련 controller 클래스 이다.
 *
 * @author : John_Kim <cale9797@gmail.com>
 * @date : 13. 4. 10.
 */
@Controller
@RequestMapping(value = "/waitingLogController")
public class WaitingLogController {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(WaitingLogController.class);

    @Autowired
    private WaitingLogService waitingLogService;

    /**
     * 로그를 등록 한다.
     *
     * @param waitingLog
     * @throws Exception
     */
    @RequestMapping(value="/registerLog", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public void registerLog(@RequestBody WaitingLog waitingLog) throws Exception {

        logger.info("registerLog");

        logger.info("merchantId   : {}", waitingLog.getMerchantId());
        logger.info("qrCode       : {}", waitingLog.getQrCode());
        logger.info("phoneNumber  : {}", waitingLog.getPhoneNumber());
        logger.info("parameter01  : {}", waitingLog.getParameter01());
        logger.info("parameter02  : {}", waitingLog.getParameter02());
        logger.info("parameter03  : {}", waitingLog.getParameter03());
        logger.info("parameter04  : {}", waitingLog.getParameter04());
        logger.info("parameter05  : {}", waitingLog.getParameter05());
        logger.info("registerDate : {}", waitingLog.getRegisterDate());

        try {
            this.waitingLogService.registerLog(waitingLog);
            logger.info("success to register log.");
        } catch (Exception e) {
            logger.error("fail to register log.");
        }
    }

    /**
     * 로그 목록을 가져 온다.
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value="/selectLogList", method = RequestMethod.POST, produces="application/json")
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public List<WaitingLog> selectLogList() throws Exception {
        logger.info("selectLogList");
        return waitingLogService.selectLogList();
    }
}
